package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.pojo.DtsBrand;
import com.qf.pojo.DtsUser;
import com.qf.service.DtsAdminService;
import com.qf.service.DtsBrandService;
import com.qf.service.DtsCategoryService;
import com.qf.util.ResponseUtil;
import com.qf.vo.CatVo;
import com.qf.vo.DtsBrandVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author YDW
 * projectName:shop-manage
 * time:2022/5/23 21:37
 * description:
 */
@RestController
@RequestMapping("/admin/brand")
public class AdminBrandController {

    @Autowired
    DtsAdminService adminService;

    @Autowired
    DtsCategoryService categoryService;

    @Autowired
    DtsBrandService brandService;

    @RequiresPermissions("admin:brand:list")
    @RequiresPermissionsDesc(menu = { "商场管理", "品牌制造商" }, button = "查询")
    @GetMapping("/list")
    public Object list(
            @RequestParam(name = "page",required = false,defaultValue = "1") Integer page,
            @RequestParam(name = "limit",required = false,defaultValue = "10") Integer limit,
            String sort,String order, Integer id,String name
    ){
        IPage<DtsBrand> ipage=brandService.queryPage(page,limit,sort,order,id,name);
        Map<String,Object> data=new HashMap<>();
        data.put("total",ipage.getTotal());
        data.put("items",ipage.getRecords());
        return ResponseUtil.ok(data);
    }

    @GetMapping("/catAndAdmin")
    public Object catAndAdmin(){
        //查询分类列表
        List<CatVo> catVos=categoryService.findCategoryList();

        //查询用户数据数据
        List<Map<String,Object>> brands=adminService.findAdmin();
        Map<String,Object> data=new HashMap<>();
        data.put("categoryList",catVos);
        data.put("adminList",brands);
        return ResponseUtil.ok(data);
    }


    @RequiresPermissions("admin:brand:create")
    @RequiresPermissionsDesc(menu = { "商场管理", "品牌制造商" }, button = "新增")
    @PostMapping("/create")
    public Object create(@RequestBody DtsBrandVo brand){

        return brandService.insert(brand);

    }

    @RequiresPermissions("admin:brand:update")
    @RequiresPermissionsDesc(menu = { "商场管理", "品牌制造商" }, button = "更新")
    @PostMapping("/update")
    public Object update(@RequestBody DtsBrandVo brand){

        return brandService.update(brand);

    }

    @RequiresPermissions("admin:brand:delete")
    @RequiresPermissionsDesc(menu = { "商场管理", "品牌制造商" }, button = "删除")
    @PostMapping("/delete")
    public Object delete(@RequestBody DtsBrand brand){
        return brandService.delete(brand);


    }
}
